<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>新增门店</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../bangnuo/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../bangnuo/admin/style/admin.css" media="all">

</head>

<body>

<div class="layui-form" lay-filter="layuiadmin-upload-useradmin" id="layuiadmin-upload-useradmin"
     style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-inline">
            <input type="text" id="merchantsAddress" name="merchantsAddress" lay-verify="required" placeholder="请输入地址"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">门店名称</label>
        <div class="layui-input-inline">
            <input type="text" name="merchantsName" id="merchantsName" lay-verify="name" placeholder="请输入门店名称"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">选择商户</label>
        <div class="layui-input-block">
            <select name="agentIdAgentId" id="agentIdAgentId">
            </select>
        </div>
    </div>
    <!--<div class="layui-form-item">
        <label class="layui-form-label">门头照</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="permissionsPictureDoor"><i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <span id="permissionsPictureDoor1"></span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">店内照</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="permissionsPictureStore"><i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <span id="permissionsPictureStore1"></span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">收银台照</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="permissionsPictureCheckstand"><i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <span id="permissionsPictureCheckstand1"></span>
        </div>
    </div>-->

</div>

<div class="layui-btn-container" style="padding-bottom: 10px; margin-left: 110px; margin-right: -110px;">
    <button class="layui-btn" lay-submit lay-filter="admin-form" data-type="close">立即提交</button>
</div>
<script src="../../bangnuo/admin/layui/layui.js"></script>
<script type="text/javascript" src="../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>

<script>
    layui.use(['form', 'upload', 'layer'], function () {

        var form = layui.form;

        var resultData;
        var htmls = '<option value="">请选择</option>'; //全局变量

        //检查项目添加到下拉框中
        $.ajax({
            url: '/commercial/name',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                resultData = data.queryResult.list;
                for (var x in resultData) {
                    htmls += '<option value = "' + resultData[x].id + '">' + resultData[x].companyName + '</option>';
                }
                $("#agentIdAgentId").html(htmls);
                form.render('select');
                //重新渲染 固定写法
            }
        })
    });
</script>
<!--加载表单组件样式-->
<script>
    /* layui.config({
         base: '../../bangnuo/admin/' //静态资源所在路径
     }).extend({
         index: 'lib/index' //主入口模块
     }).use(['index', 'form', 'upload'], function () {
         var $ = layui.$,
             form = layui.form,
             upload = layui.upload;

         /!*upload.render({
             elem: '#layuiadmin-upload-useradmin',
             url: layui.setter.base + 'json/upload/demo.js',
             accept: 'images',
             method: 'get',
             contentType: "application/json",
             acceptMime: 'image/!*',
             done: function (res) {
                 $(this.item).prev("div").children("input").val(res.data.src)
             }
         });*!/
     })*/
</script>
<!--获取表单信息，提交表单-->
<!--<script>
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/upload/'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        })
</script>-->
<script type="text/javascript">

    layui.use(['form', 'upload'], function () {



        var url = window.location.href;
        //获取“=”的下标
        var pos = url.indexOf("=");
        //获取“=”后的全部字符（用户id）
        var id = url.substring(pos + 1, url.length);
        var imageList = {};
        var file = {};

        var form = layui.form,
            upload = layui.upload;
        //监听提交
        form.on('submit(admin-form)', function (data) {
            file.merchantsAddress = $('#merchantsAddress').val();
            file.merchantsName = $('#merchantsName').val();
            file.imageList = imageList;
            file.agentIdAgentId = $('#agentIdAgentId').val();
            $.ajax({
                url: "/merchantsEntity/addMerchants",
                contentType: "application/json;charset=UTF-8",
                type: "POST",
                data: JSON.stringify(file),
                dataType: "json",
                success: function (res) {
                    if (res.success) {
                        console.log("图片资源更新成功", res);
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        console.log("index值", index)
                        close();
                    } else {
                        console.log("图片资源更新失败", res);
                    }
                }
            });
        });
        //门头照
        var uploadInst = upload.render({
            elem: '#permissionsPictureDoor' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureDoor1").html("上传成功");
                    imageList.permissionsPictureDoor = res.object.webPath;
                } else {
                    $("#permissionsPictureDoor").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureDoor1").html("上传失败，请重新上传");
            }
        });

        //店内照
        var uploadInst = upload.render({
            elem: '#permissionsPictureStore' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureStore1").html("上传成功");
                    imageList.permissionsPictureStore = res.object.webPath;
                } else {
                    $("#permissionsPictureStore1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureStore1").html("上传失败，请重新上传");
            }
        });

        //收银台照
        var uploadInst = upload.render({
            elem: '#permissionsPictureCheckstand' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureCheckstand1").html("上传成功");
                    imageList.permissionsPictureCheckstand = res.object.webPath;
                } else {
                    $("#permissionsPictureCheckstand1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureCheckstand1").html("上传失败，请重新上传");
            }
        });

        //身份证照正
        var uploadInst = upload.render({
            elem: '#permissionsPictureCardPositive' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureCardPositive1").html("上传成功");
                    imageList.permissionsPictureCardPositive = res.object.webPath;
                } else {
                    $("#permissionsPictureCardPositive1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureCardPositive1").html("上传失败，请重新上传");
            }
        });

        //身份证照反
        var uploadInst = upload.render({
            elem: '#permissionsPictureCardReverse' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureCardReverse1").html("上传成功");
                    imageList.permissionsPictureCardReverse = res.object.webPath;
                } else {
                    $("#permissionsPictureCardReverse1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureCardReverse1").html("上传失败，请重新上传");
            }
        });


        //手持身份证照
        var uploadInst = upload.render({
            elem: '#permissionsPictureHandheld' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureHandheld1").html("上传成功");
                    imageList.permissionsPictureHandheld = res.object.webPath;
                } else {
                    $("#permissionsPictureHandheld1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureHandheld1").html("上传失败，请重新上传");
            }
        });


        //银行卡照
        var uploadInst = upload.render({
            elem: '#permissionsPictureBank' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureBank1").html("上传成功");
                    imageList.permissionsPictureBank = res.object.webPath;
                } else {
                    $("#permissionsPictureBank1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureBank1").html("上传失败，请重新上传");
            }
        });


        //营业执照
        var uploadInst = upload.render({
            elem: '#permissionsPictureBusiness' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureBusiness1").html("上传成功");
                    imageList.permissionsPictureBusiness = res.object.webPath;
                } else {
                    $("#permissionsPictureBusiness1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureBusiness1").html("上传失败，请重新上传");
            }
        });


        //资质许可证
        var uploadInst = upload.render({
            elem: '#permissionsPictureQualification' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureQualification1").html("上传成功");
                    imageList.permissionsPictureQualification = res.object.webPath;
                } else {
                    $("#permissionsPictureQualification1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureQualification1").html("上传失败，请重新上传");
            }
        });




    });


    /*layui.use(['form', 'upload'], function () {

        var $ = layui.jquery;
        //var url = window.location.href;
        //获取“=”的下标
        //var pos = url.indexOf("=");
        //获取“=”后的全部字符（用户id）
        // var id = url.substring(pos+1,url.length);
        var imageList = {};
        var form = layui.form,
            upload = layui.upload;

        var file = {};
        file.merchantsAddress = data.field.merchantsAddress;
        file.merchantsName = data.field.merchantsName;
        file.imageList = imageList;
        //监听提交
        form.on('submit(admin-form)', function (data) {
            $.ajax({
                type: "post",
                url: "merchantsEntity/addMerchants",
                contentType: "application/json",
                dataType: 'json',
                data: JSON.stringify(file),
                async: true,
                success: function (data) {
                    if (data.success == true) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
            return false;
        });
        //门头照
        var uploadInst = upload.render({
            elem: '#permissionsPictureDoor' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureDoor1").html("上传成功");
                    imageList.permissionsPictureDoor = res.object.webPath;
                } else {
                    $("#permissionsPictureDoor").html("上传失败，请重新上传");
                }
            },
            error: function () {
                $("#permissionsPictureDoor1").html("上传失败，请重新上传");
            }
        });

        //店内照
        var uploadInst = upload.render({
            elem: '#permissionsPictureStore' //绑定元素
            ,
            url: '/upload/img' //上传接口
            ,
            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureStore1").html("上传成功");
                    imageList.permissionsPictureStore = res.object.webPath;
                } else {
                    $("#permissionsPictureStore1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureStore1").html("上传失败，请重新上传");
            }
        });

        //收银台照
        var uploadInst = upload.render({
            elem: '#permissionsPictureCheckstand', //绑定元素

            url: '/upload/img', //上传接口

            done: function (res) {
                if (res.success) {
                    console.log("上传成功", res);
                    $("#permissionsPictureCheckstand1").html("上传成功");
                    imageList.permissionsPictureCheckstand = res.object.webPath;
                } else {
                    $("#permissionsPictureCheckstand1").html("上传失败，请重新上传");
                }

            },
            error: function () {
                $("#permissionsPictureCheckstand1").html("上传失败，请重新上传");
            }
        });

    });*/
</script>
<!--关闭弹层-->
<!--<script>
    layui.use('layer', function() {
        var $ = layui.$,
            layer = layui.layer,
            index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var active = {
            close: function() {
                var id = '#LAY_layer_iframe_demo',
                    mark = $('#LAY_mark');
                parent.layer.msg('添加成功');
                parent.layer.tips('Look here', id, {
                    time: 5000
                });
                parent.layer.close(index);
            }
        }
        $('.layui-btn-container .layui-btn').on('click', function() {
            var othis = $(this),
                type = othis.data('type');
            active[type] && active[type].call(this);
        });
    });
</script>-->
</body>

</html>